/* *******************************************************************************
 * Add by  : Jenny Li 
 * Add date: 2006/09/26
 * Description:  The Js function for EditEmailArchiveRule.jsp 
 * *********************************************************************************************
 */
 

function saveCheck(){
  var frm;
  for (var i = 0; i < document.forms.length; i++) {
    if (document.forms[i].name != "") {
      frm = document.forms[i];
      break;
    }
  }
  var notifyNum=0;
  
 }
  


function popupComplexPanel(rootID, parentID, displayField, hiddenField,pageFlag) {
  var frm;
  for (var i = 0; i < document.forms.length; i++) {
    if (document.forms[i].name != "") {
      frm = document.forms[i];
      break;
    }
  }  
  
  var url = contextPath + "/dms/MaintDmsPopComplex.do";
  var name = "DCIVisionPopupDmsComplexPanel";
  var popW = "650";
  var popH = "550";
  var feature = "scrollbars=yes,resizable=yes";

  return OpenCenteredPopup(url, name, popW, popH, feature);
}

function reSetPage(showValue,hiddenValue,index,passValue, ID){
  window.setTimeout("reSetPageSubmit('"+showValue+"', '"+hiddenValue+"','"+index+"','"+passValue+"','"+ID+"')",0);
}

function reSetPageSubmit(showValue,hiddenValue,index,passValue, ID){
  var frm;
  for (var i = 0; i < document.forms.length; i++) {
    if (document.forms[i].name != "") {
      frm = document.forms[i];
      break;
    }
  } 
  //alert("userPickerID:"+ID);      
  if (showValue == "") {
    //alert("User(s) is required!");      
    return false;
  } else {      
    EmailRuleEngineHelper.addCondition(displayCondSpanAddCondSpan, hiddenValue, showValue, maintEmailArchiveRuleForm.relation[0].checked, ID);        
  }   
}

function OpCustSetRecordID(value, fullName, ruleID) {  
  window.setTimeout("OpCustSetRecordIDSelect('"+value+"', '"+fullName+"',"+ruleID+")",0);
}

function OpCustSetRecordIDSelect(value, fullName, ruleID) {  
  hideDivs("");  
  EmailRuleEngineHelper.checkPermission(errorHandle, value, fullName, ruleID);
    
}

function errorHandle(content){ 
  if(content.indexOf("N##") == 0){
    alert(content.substring(3) );
    return false;
  } else {
    //EmailRuleEngineHelper.addSubmitter(displayActionSpanAddActionSpan, value, fullName, ruleID); 
    displayActionSpanAddActionSpan(content);
  }
}

function showTab(b) {
   
   var stepNavigationContent = "";
   
   if ("RuleConditionDiv" == b) {
     FindObj('RuleConditionDiv').style.display = 'block';
     FindObj('RuleActionDiv').style.display = 'none';
     FindObj('RuleContentDiv').style.display = 'none';
     
     FindObj('RuleConditionDivTab').style.color ="#0000AA";
     FindObj('RuleActionDivTab').style.color ="#000000";
     FindObj('RuleContentDivTab').style.color ="#000000";
     
     stepNavigationContent = "<a href=\'#\' onclick=\"return showTab(\'RuleActionDiv\')\">" + nextImage + "</a>";
   
   } else if ("RuleActionDiv" == b) {        
     FindObj('RuleConditionDiv').style.display = 'block';
     FindObj('RuleActionDiv').style.display = 'block';
     FindObj('RuleContentDiv').style.display = 'none';
     
     FindObj('RuleConditionDivTab').style.color ="#000000";
     FindObj('RuleActionDivTab').style.color ="#0000AA";
     FindObj('RuleContentDivTab').style.color ="#000000";
     
     stepNavigationContent = "<a href=\'#\' onclick=\"return showTab(\'RuleConditionDiv\')\">" + previousImage + "</a>";
     stepNavigationContent += "&nbsp;&nbsp;<a href=\'#\' onclick=\"return showTab(\'RuleContentDiv\')\">" + nextImage + "</a>";
     
   } else {
     FindObj('RuleConditionDiv').style.display = 'block';
     FindObj('RuleActionDiv').style.display = 'block';
     FindObj('RuleContentDiv').style.display = 'block';
     
     FindObj('RuleConditionDivTab').style.color ="#000000";
     FindObj('RuleActionDivTab').style.color ="#000000";
     FindObj('RuleContentDivTab').style.color ="#0000AA";
     
     stepNavigationContent = "<a href=\'#\' onclick=\"return showTab(\'RuleActionDiv\')\">" + previousImage + "</a>";
   }
   
   stepNavigationSpan.innerHTML = stepNavigationContent;
}

 var xMouse = 240;
 var yMouse = 360;
 var hasThreeOption = false;  
 var addMore = false;  

 function Mouse(evnt){ 
   xMouse = event.x - 10;
   yMouse = event.y + 5;
 }
 
 function onChangeFolderPicker(targetPath, rootID, parentID, ID){  
 	 var tmpPath = escape(targetPath);
   window.setTimeout("onChangeFolderPickerSelect('"+tmpPath+"', "+rootID+","+parentID+","+ID+")",0);
 }
  
 function onChangeFolderPickerSelect(targetPath, rootID, parentID, ID){     
   var frm;
   for (var i = 0; i < document.forms.length; i++) {
     if (document.forms[i].name != "") {
       frm = document.forms[i];
       break;
     }
   }    
   var folderPath = unescape(targetPath);   
   var value = rootID + "|" + parentID;   
   EmailRuleEngineHelper.addAction(displayActionSpanAddActionSpan,value,folderPath,ID);     
 }
 

 
 function OpCusSave() {
   addMore = false;
   EmailRuleEngineHelper.checkRule(checkRule);   
 }
 
 function OpCusSaveAndNew() {
  addMore = true;
  EmailRuleEngineHelper.checkRule(checkRule);
 }  
 
 function OpValidate(){
  var frm;
  for (var i = 0; i < document.forms.length; i++) {
    if (document.forms[i].name != "") {
      frm = document.forms[i];
      break;
    }
  }     
  return EmailRuleEngineHelper.checkRule(checkRule);  
 }  
 
 
 
 function changeRuleRelation(object){
   EmailRuleEngineHelper.getOldCondition(displaySpan, object.value == "A");
 }  
   
 function displayDiv(divName, display){
   hideDivs(divName);
   if (display) {     
     FindObj(divName).style.left = xMouse;
     FindObj(divName).style.top = yMouse;
     ShowDiv(divName);    
   } else {
     HideDiv(divName);
   }   
   
 }
 
 
 function displayText(){
   var str="";
   str += "<input type=\'text\' name=\'value\' onBlur=\'checkValue(this)\' size=\'20\' style=\"Border-top-width=0; Border-right-width=0; Border-left-width=0; Border-botto m-width=1\">";   
   conditionSpan.innerHTML = condition + str ;   
 }
 
 function checkValue(object, id){ 
   
   if (object.value == "") {
     return false;
   } else { //alert(object.value);
     EmailRuleEngineHelper.addCondition(displayCondSpanAddCondSpan, object.value, object.value, maintEmailArchiveRuleForm.relation[0].checked, id);        
   }
 }
 
  function doNothing() {}
  

  function displaySpan(content){    
    condSpan.innerHTML = content;        
  }
  
  function displayOption1(content){
    condSpan.innerHTML = content;
    addCondSpan.innerHTML = "";
  } 
  
  function displayCondSpanAddCondSpan(content){
    condSpan.innerHTML = content;    
    if (content.indexOf("&lt;") == -1 && content.indexOf("<input") == -1) {
      addCondSpan.innerHTML = "<a href=\'#\' onclick=\'newCondition()\' >[+]</a>";
    }
  }
    
  
  function displayAddCondSpan(context){ 
    if ( context == isTrue) {
      addCondSpan.innerHTML = "<a href=\'#\' onclick=\'newCondition()\' >[+]</a>";
    } else {
      addCondSpan.innerHTML = "";
    }    
  }
  
  
  function newCondition(){  
    EmailRuleEngineHelper.newCondition(displayOption1, language, maintEmailArchiveRuleForm.relation[0].checked);       
    EmailRuleEngineHelper.displayCondPlus(displayAddCondSpan);    
  }
   
  function selectedJudgement(conditionValue, conditionDesc, divName){ 
    hideDivs(divName);  
    EmailRuleEngineHelper.getOption3(displaySpan, conditionValue, conditionDesc, maintEmailArchiveRuleForm.relation[0].checked);    
    EmailRuleEngineHelper.displayCondPlus(displayAddCondSpan);    
  }
  
  function removeCondition(deleteItem){
    EmailRuleEngineHelper.removeCondition(displaySpan, deleteItem, maintEmailArchiveRuleForm.relation[0].checked);   
    //EmailRuleEngineHelper.displayCondPlus(displayAddCondSpan); 
  }
  
  function changeTextBox(ID){  //alert("textID:"+ID);
    EmailRuleEngineHelper.changeTextBox(displayCondSpanAddCondSpan, '"+isAnd+"', ID);
  }
  
  function hideDivs(divName){ 
    if (divName != 'conditionDiv') {
      if (FindObj('conditionDiv')) {
        HideDiv('conditionDiv');
      }
    } 
    
    if (divName != 'judgementDiv-1') {
      if (FindObj('judgementDiv')) {
        HideDiv('judgementDiv');
      }
    } 
    
    if (divName != 'actionDiv') {
      if (FindObj('actionDiv')) {
        HideDiv('actionDiv');
      }
    } 
    
    for (var i=-1; i<100; i++) {
      if (divName != "notifyDiv" + i) {
        if (FindObj('notifyDiv' + i)) {
          HideDiv('notifyDiv' + i);
        }
      }
    }
    
    for (var i=-1; i<100; i++) {
      if (divName != "workflowDiv" + i) {
        if (FindObj('workflowDiv' + i)) {
          HideDiv('workflowDiv' + i);
        }
      }
    }      
     
  }
  
  //==============================Action=====================
  function displayActionSpan(content){
    actionSpan.innerHTML = content; 
  }
  
  
  
  function addAnAction(value, description, divName, ID){
    hideDivs(divName);
    EmailRuleEngineHelper.addAction(displayActionSpanAddActionSpan, value, description, ID); 
  }
  
  function selectSubmitter(value, description, divName, ID){
    hideDivs(divName);
    EmailRuleEngineHelper.getSubmitter(displayActionSpan, value, description, ID); 
  }
  
  function displayActionSpanAddActionSpan(content){
    actionSpan.innerHTML = content; 
    if (content.indexOf("&lt;") == -1 ) {
      addActionSpan.innerHTML = "<a href=\'#\' onclick=\'newAction()\' >[+]</a>";
    }
  }
  
  function newAction() {
    EmailRuleEngineHelper.newAction(addNewAction, language); 
  }
  
  function addNewAction(content){
    actionSpan.innerHTML = content; 
    addActionSpan.innerHTML = "";
  }
  
  function removeAction(deleteItem){
    EmailRuleEngineHelper.removeAction(displayActionSpan, deleteItem);
  }
  
  
  function submitRule(){    
    EmailRuleEngineHelper.getActionValue(setActionValue);
    EmailRuleEngineHelper.getDetailDescription(setDetailDescription, maintEmailArchiveRuleForm.relation[0].checked);
    EmailRuleEngineHelper.getConditionValue(setConditionValue);
  }
  
  function setConditionValue(context){ 
    maintEmailArchiveRuleForm.conditionValue.value = context
  }
  
  function setActionValue(context){  
    maintEmailArchiveRuleForm.actionValue.value = context;
  }
  
  function setDetailDescription(context){ 
    maintEmailArchiveRuleForm.detailDescription.value = context;
  }
  
  
  //=======================================
